package class12;

import class08.IsBalanced;

import java.util.Stack;

/**
 * @author zhangchaoliang
 * create 2022
 */
public class ReverseStackUsingRecursive3 {

    public static int f(Stack<Integer> stack){
        int result = stack.pop();
        if (stack.isEmpty()){
            return result;
        }else {
            int last = f(stack);
            stack.push(result);
            return last;
        }
    }

    public static void reverse(Stack<Integer> stack){
        if (stack.isEmpty())
            return;
        int i = f(stack);
        reverse(stack);
        stack.push(i);
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        reverse(stack);

        while (!stack.isEmpty()){
            System.out.println(stack.pop());
        }
    }
}
